#ARGV 0:	directory of log files
#ARGV 1:	number of considered rounds

 
$dir = $ARGV[0];

$start = 1;
$base = 0;
$recordNum = 1001;
$round = 7700;
if($ARGV[1]!=0){
	$round = $ARGV[1];
}

$first = 1;
$batch = 25;

$fileName = "$ARGV[0]//totalSync.info";
open fout, ">$fileName" or die "can not open file >$fileName!\n";
for($i=0;$i<=$round;$i++){
	$start = $i*($recordNum+2)+1 - $base;
	
	$cmd = "perl proLogWithSyncTimeStampBySelfDefinedInterval.pl ".$dir." ".$recordNum." ".$start;
	print "$i Round $cmd\n";
	system("$cmd\n");
	
	#sleep(1);
	
	$file_path = "$ARGV[0]/temp/totalSync".$start.".info";
	open fin, "<$file_path" or die "can not open file $file_path!\n";
	while(<fin>){
		print fout $_; 
	}
	close fin;
	
	#$cmd = "rm ".$file_path;
	#system("$cmd\n");
	#sleep(1);
	
	if($i%$batch==0){
		if($first==1){
			$deltN = 1003;
			$first = 0;
		}
		else{
			$deltN = 1003*$batch;
		}
		for($j=11;$j<27;$j++){
			$logfile = "$ARGV[0]/channel$j".".log";
			$cmd = "perl -ni -e \'print unless 1 .. $deltN\' $logfile";
			system("$cmd\n");
			print "$cmd\n";
		}
		$base = ($i+1)*($recordNum+2);
	}
}
close fout;
	